package com.datasource.util;

import java.util.Random;

public class RandomUtil {
  private static final Random random = new Random(47);
  static boolean[] used = null;

  public static int randomLength(int min, int max) {
    int result = random.nextInt(max);
    while (result < min) {
      result = random.nextInt(max);
    }

    return result;
  }

  public static void clearAndInitIdArr(int length) {
    if (used == null) {
      used = new boolean[length];
      return;
    }

    for (boolean b : used) {
      b = false;
    }
  }

  public static long randomId(int min, int max) {
    int result = randomLength(min, max);
    while (used[result]) {
      result = randomLength(min, max);
    }

    used[result] = true;
    return result;
  }
}
